package cn.edu.zafu.bigdata.x.xiejunjie;

public class StaticDemo {
    // 静态变量，记录实例数量
    static int count;

    // 实例变量，存储实例ID
    int id;

    // 静态初始化块
    static {
        System.out.println("Static block executed");
        count = 0; // 初始化静态变量
    }

    // 实例初始化块
    {
        System.out.println("Instance block executed");
        this.id = count; // 设置实例ID
        count++; // 增加实例计数
    }

    // 构造函数
    public StaticDemo() {
        System.out.println("Constructor executed for ID: " + id);
    }

    // 静态方法，显示实例数量
    public static void displayCount() {
        System.out.println("Total instances created: " + count);
    }
}
